<?php
	@header("Content-Type:text/html;charset=utf-8");
	@header("Access-Control-Allow-Origin:*");
	
	
	$conn =  mysql_connect("localhost","root","root");   
	$a = mysql_select_db("object",$conn);   //连接数据库
	
	
	$userid= $_GET["userid"];
	$goodsid = $_GET["goodsid"];
	$num= $_GET["num"];
	$account= $_GET["account"];

	if(isExist($userid,$goodsid)){
		$sql = "update mygoodslist set buy_num = buy_num+'$num',buy_account=buy_account+'$account'  where user_id='$userid' and goods_id='$goodsid'";
	}else{
		$sql = "insert into shoppingcar(user_id,goods_id,buy_num,buy_account) values('$userid','$goodsid','$num','$account')";
	}


//	echo $sql;
	mysql_query("set charset set utf-8");     //数据库输入输出编码格式
	
	$result = mysql_query($sql); 
//	
	$item = mysql_affected_rows();

	$msg = array();
	if($item&&$item==1){
		$msg["status"] = true;
		$msg["msg"] = "加入成功";
		
	}else{
		$msg["status"] = false;
		$msg["msg"] = "加入失败";
	}
	echo json_encode($msg);


	function isExist($userid,$goodsid){
		$sql = "select * from shoppingcar where user_id='$userid' and goods_id='$goodsid'";
//		echo $sql;
		$reslut = mysql_query($sql);
		$row = mysql_affected_rows();
		if($row){
			return true;
		}else{
			return false;
		}
	}
	
?>